package net.kunyv.base.service;


import net.kunyv.base.entity.SysUserRole;
import net.kunyv.base.mapper.SysUserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 用户角色servcie
 *
 * @author sunyb
 * @date 2017-08-02
 */
@Service
public class SysUserRoleService extends BaseService<SysUserRole> {
    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    /**
     * 获取用户拥有的角色列表
     *
     * @param userId
     * @return java.util.List<net.kunyv.entity.SysUserRole>
     * @throw
     * @author sunyb
     * @date 2018/11/19
     */
    public List<SysUserRole> getUserRoleByUserId(String userId) {
        Example example = new Example(SysUserRole.class);
        example.createCriteria().andEqualTo("userId", userId);
        return sysUserRoleMapper.selectByExample(example);
    }

    /**
     * 查询未拥有该角色的用户
     *
     * @param roleId
     * @return java.util.List
     * @author sunyb
     * @date 2018/12/7
     */
    public List selectNotHaveUser(String roleId, String userName) {
        return sysUserRoleMapper.selectNotHaveUser(roleId, userName);
    }

    /**
     * 查询拥有该角色的用户
     *
     * @param roleId
     * @return java.util.List
     * @author sunyb
     * @date 2018/12/7
     */
    public List selectRoleUser(String roleId) {
        return sysUserRoleMapper.selectRoleUser(roleId);
    }
}
